﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;

namespace Lib
{
    public static class Tool
    {
        public static Color GetColorFromString(string colorString)
        {
            Color result = Colors.Black;

            try
            {
                colorString = colorString.ToUpper().Trim('#');
                string a = "0x" + colorString.Substring(0, 2);
                string r = "0x" + colorString.Substring(2, 2);
                string g = "0x" + colorString.Substring(4, 2);
                string b = "0x" + colorString.Substring(6, 2);


                byte A = Convert.ToByte(a, 16);
                byte R = Convert.ToByte(r, 16);
                byte G = Convert.ToByte(g, 16);
                byte B = Convert.ToByte(b, 16);

                result = Color.FromArgb(A, R, G, B);

            }
            catch { }

            return result;
        }
    }
}
